#!/bin/bash /route/moth/etc/mb

MLIBPATH=/data/project/tang/route/xiaomi/OpenWrt-SDK-ramips-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package/libev-4.27/.libs
APPDIR=/route/moth

# export MOTH_API_URL=http://192.168.40.22:18279
# export MOTH_WS_URL=ws://192.168.40.22:38728

moth_id() {
    echo -n "PC|07233-4456456"
}

moth_status() {
    ps -aux | grep $APPNAME
}

moth_version() {
    echo -n "PC|v1"
}

r3_copy_file() {
    local workdir="$1"
    local name="$2"
    find $workdir/etc/usr/$name -type l | while read filepath; do
        mv $filepath $workdir/usr/$name/
    done
    find $workdir/etc/usr/$name -type f | while read filepath; do
        ln -sf /etc/usr/$name/$(basename $filepath) $workdir/usr/$name/
    done
}

moth_r3() {
    local workdir=$APPDIR/r3

    cd $workdir

    rm -rf $workdir/etc $workdir/usr

    cp -rf $APPDIR/etc $workdir/
    cp -rf $APPDIR/usr $workdir/etc/

    mkdir -p usr/bin
    mkdir -p usr/lib

    mv $workdir/etc/usr/share $workdir/usr/
    # mv $workdir/etc/usr/sbin $workdir/usr/

    # mv $workdir/etc/usr/bin/himan $workdir/usr/bin/

    r3_copy_file $workdir bin
    r3_copy_file $workdir lib

    mv $workdir/etc/mb $workdir/usr/bin/

    cd ..
    local tarfile=/route/ant/r3.tar.gz
    rm -f $tarfile
    tar -czf $tarfile r3
    /works/deploy/cli cossh tang-ad push $tarfile /works/res/r3.tar.gz
}

